package com.woniuxy.three.pms.vip.service.impl;

import com.woniuxy.three.pms.bean.VipBean;
import com.woniuxy.three.pms.dao.VipBeanMapper;
import com.woniuxy.three.pms.vip.service.IVipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ProjectName: Pms
 * @Package: com.woniuxy.three.pms.vip.service.impl
 * @ClassName: VipServiceImpl
 * @Author: 12092
 * @Description: 会员的等级业务
 * @Date: 2019/6/28 9:50
 * @Version: 1.0
 */
@Service("vipServiceImpl")
public class VipServiceImpl implements IVipService {

    @Autowired
    private VipBeanMapper vipBeanMapper;

    /***
     * 修改VIP等级
     * 需要传递的对象中至少存在一个VIP 的名称 即 message字段
     * @param vipBean
     * @return
     */
    @Override
    public boolean modifyVipPreferential(VipBean vipBean) {
    	System.out.println(vipBean);
        //查找 对应对象的ID
        VipBean findVipByName = null;
        if (vipBean.getId()==null){
            findVipByName = vipBeanMapper.selectByVipName(vipBean.getMessage());
            vipBean.setId(findVipByName.getId());
        }
        //执行修改
        int updateResult = vipBeanMapper.updateByPrimaryKeySelective(vipBean);
        if (updateResult>0){
            return true;
        }
        return false;
    }

    /***
     * 查询所有的Vip等级
     * @return
     */
    @Override
    public List<VipBean> findAllVip() {
        return vipBeanMapper.findAllVip();
    }

    /**
     * 新增VIP等级
     * @param vipBean
     * @return
     */
    @Override
    public boolean addVip(VipBean vipBean) {
        int insertResult = vipBeanMapper.insertSelective(vipBean);
        if (insertResult>0){
            return true;
        }
        return false;
    }

    /**
     * 删除VIP等级
     * @param id
     * @return
     */
    @Override
    public boolean delVip(Integer id) {
        int deleteResult = vipBeanMapper.deleteByPrimaryKey(id);
        if (deleteResult > 0){
            return true;
        }
        return false;
    }
    
    @Override
    public VipBean findById(Integer id) {
    	VipBean vip = vipBeanMapper.selectByPrimaryKey(id);
    	return vip;
    }
}
